<template>
	<view class="container">
		<view>
			<u-picker :show="show" :columns="columns" :title="title" @cancel="show = false" @confirm="confirm"></u-picker>
      <u-datetime-picker :minDate="newData" :show="dateTimeShow" mode="datetime" :title="title"
                         @cancel="dateTimeShow =false" @confirm="checkDateTime"></u-datetime-picker>
			<u--form labelPosition="left" :model="from" :rules="rules" ref="form1" labelWidth='120px'
				:labelStyle='labelStyle'>
				<view class="title">
					基础信息
				</view>
				<view class="box">
          <u-form-item label="作业票名称" prop="zypmc" borderBottom>
            <u--input v-model="from.zypmc" placeholder="输入作业票名称" border="none"></u--input>
          </u-form-item>
					<u-form-item label="作业申请单位" prop="zysqdw" borderBottom @click="show = true,showType = 1">
						<u--input v-model="from.zysqdw" placeholder="选择危害因素" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="作业申请时间" prop="createTime" borderBottom @click="dateTimeShow =true,dateTimeType=1">
						<u--input v-model="from.createTime" placeholder="选择作业申请时间" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="作业实施时间" prop="zysssj" borderBottom @click="dateTimeShow =true,dateTimeType=2">
						<u--input v-model="from.zysssj" placeholder="选择作业实施时间" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
          <user-pick
              :label="'监护人'"
              :multiple="false"
              :title="'监护人'"
              :placeholder="'请选择监护人'"
              v-model="from.dhr"
              :prop="'jhr'"
          ></user-pick>
					<view style="color: #838383;padding: 0 0 10px 0">作业内容</view>
					<u--textarea v-model="from.zynnr" placeholder="请输入..." height="120" confirmType="next"
						style="margin-bottom: 15px;background: #f6f6f6" count :maxlength="500"></u--textarea>
					<u-form-item label="受限空间名称" prop="sxkjmc" borderBottom>
						<u--input v-model="from.sxkjmc" placeholder="输入受限空间名称" border="none"></u--input>
					</u-form-item>
          <user-pick
              :label="'作业人'"
              :multiple="false"
              :title="'作业人'"
              :placeholder="'请选择作业人'"
              v-model="from.zyr"
              :prop="'zyr'"
          ></user-pick>
					<u-form-item label="作业单位" prop="zydw" borderBottom @click="show = true,showType = 4">
						<u--input v-model="from.zydw" placeholder="选择作业单位" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
          <user-pick
              :label="'施工负责人'"
              :multiple="false"
              :title="'施工负责人'"
              :placeholder="'请选择施工负责人'"
              v-model="from.sgfzr"
              :prop="'sgfzr'"
          ></user-pick>
					<u-form-item label="介质名称" prop="sxkjnyyjzmc" borderBottom>
						<u--input v-model="from.sxkjnyyjzmc" placeholder="输入介质名称" border="none"></u--input>
					</u-form-item>

				</view>
				<view class="title">
					关联特殊作业
				</view>
				<view class="box">
					<u-form-item label="关联特殊作业" prop="gltszy" @click="show = true,showType = 6">
						<u--input v-model="from.gltszy" placeholder="选择关联特殊作业" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
				</view>
				<view class="title">
					气体检测
				</view>
				<view class="box">
					<u-form-item label="取样分析时间" prop="ydyhydyhqyfxsj" borderBottom @click="dateTimeShow =true,dateTimeType=3">
						<u--input v-model="from.ydyhqyfxsj" placeholder="选择取样分析时间" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="有毒有害气体" prop="harmfulGas" borderBottom>
						<u--input v-model="from.harmfulGas" placeholder="输入有毒有害气体名称" border="none"></u--input>
					</u-form-item>
					<u-form-item label="合格标准" prop="ydyhhgbz" borderBottom>
						<u--input v-model="from.ydyhhgbz" placeholder="输入有毒有害气体合格标准" border="none"></u--input>
					</u-form-item>
					<u-form-item label="氧气含量" prop="ydyhqtyqhl" borderBottom>
						<u--input v-model="from.ydyhqtyqhl" placeholder="输入氧气含量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="分析部位" prop="yhqtfxbw" borderBottom>
						<u--input v-model="from.yhqtfxbw" placeholder="输入分析部位" border="none"></u--input>
					</u-form-item>
<!--					<u-form-item label="分析数据" prop="userInfo.name" borderBottom>-->
<!--						<u&#45;&#45;textarea v-model="from.test" placeholder="请输入有毒有害气体分析结果……" confirmType="next"></u&#45;&#45;textarea>-->
<!--					</u-form-item>-->
          <view style="color: #838383;padding: 10px 0">分析数据</view>
          <u--textarea v-model="from.ydyhfxjg" placeholder="请输入有毒有害气体分析结果..." height="120" confirmType="next"
                       style="margin-bottom: 15px;background: #f6f6f6" count :maxlength="500"></u--textarea>
					<u-form-item label="取样分析时间" prop="krqtfxsj" borderBottom @click="dateTimeShow =true,dateTimeType=4">
						<u--input v-model="from.qyfxsj" placeholder="选择取样分析时间" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="可燃气体" prop="krqtmc" borderBottom>
						<u--input v-model="from.krqtmc" placeholder="输入可燃气体气体名称" border="none"></u--input>
					</u-form-item>
					<u-form-item label="合格标准" prop="krqthgbz" borderBottom>
						<u--input v-model="from.krqthgbz" placeholder="输入可燃气体合格标准" border="none"></u--input>
					</u-form-item>
					<u-form-item label="氧气含量" prop="krtqyqhl" borderBottom>
						<u--input v-model="from.krtqyqhl" placeholder="输入氧气含量" border="none"></u--input>
					</u-form-item>
					<u-form-item label="分析部位" prop="krqtfxbw" borderBottom>
						<u--input v-model="from.krqtfxbw" placeholder="输入分析部位" border="none"></u--input>
					</u-form-item>
          <view style="color: #838383;padding: 10px 0">分析数据</view>
          <u--textarea v-model="from.krqtfxsj2" placeholder="请输入可燃气体分析结果" height="120" confirmType="next"
                       style="margin-bottom: 15px;background: #f6f6f6" count :maxlength="500"></u--textarea>
          <user-pick
              :label="'分析人'"
              :multiple="false"
              :title="'分析人'"
              :placeholder="'请选择分析人'"
              v-model="from.fxr"
              :prop="'fxr'"
          ></user-pick>
				</view>
				<view class="title">
					危害辨识-安全措施
				</view>
        <view class="box" style="padding-bottom: 6px">
          <u-form-item label="危害辨识" prop="text" borderBottom @click="toHazardousFactors">
            <u--input v-model="from.text" placeholder="选择危害因素" border="none" disabled
                      disabledColor="#ffffff"></u--input>
            <u-icon slot="right" name="arrow-right"></u-icon>
          </u-form-item>
          <view
              style="background:#f6f6f6;margin-bottom: 30px;border-radius:8px;height: 200px;overflow-y: auto">
            <u-checkbox-group v-model="from.harm" placement="column" :labelSize='32'>
              <u-checkbox activeColor="#53c21d" v-for="(item,index) in from.  harm" :label="item.label"
                          :name="item.value" shape="circle" :key="index" style="padding: 10px 20px" :checked=true>
              </u-checkbox>
            </u-checkbox-group>
          </view>
          <u-form-item label="安全措施" prop="text" borderBottom @click="toSafetyMeasures">
            <u--input v-model="from.text" placeholder="选择安全措施" border="none" disabled
                      disabledColor="#ffffff"></u--input>
            <u-icon slot="right" name="arrow-right"></u-icon>
          </u-form-item>
          <view
              style="background:#f6f6f6;margin-bottom: 30px;border-radius:8px;height: 200px;overflow-y: auto">
            <u-checkbox-group v-model="from.safetyMeasures" placement="column" :labelSize='32'>
              <u-checkbox activeColor="#53c21d" v-for="(item,index) in from.safetyMeasures"
                          :label="item.label" :name="item.value" shape="circle" :key="index"
                          style="padding: 10px 20px" :checked=true>
              </u-checkbox>
            </u-checkbox-group>
          </view>
          <u-form-item label="个人用品防护" prop="text" borderBottom @click="toProtection">
            <u--input v-model="from.text" placeholder="选择个人用品防护" border="none"></u--input>
            <u-icon slot="right" name="arrow-right"></u-icon>
          </u-form-item>
          <view
              style="background:#f6f6f6;margin-bottom: 30px;border-radius:8px;height: 200px;overflow-y: auto">
            <u-checkbox-group v-model="from.personalProtection" placement="column" :labelSize='32'>
              <u-checkbox activeColor="#53c21d" v-for="(item,index) in from.personalProtection"
                          :label="item.label" :name="item.value" shape="circle" :key="index"
                          style="padding: 10px 20px" :checked=true>
              </u-checkbox>
            </u-checkbox-group>
          </view>
        </view>
				<view class="title">
					安全交底
				</view>
				<view class="box">
          <user-pick
              :label="'安全交底人'"
              :multiple="false"
              :title="'安全交底人'"
              :placeholder="'请选择安全交底人'"
              v-model="from.aqjdr"
              :prop="'aqjdr'"
          ></user-pick>
          <user-pick
              :label="'接受交底人'"
              :multiple="false"
              :title="'接受交底人'"
              :placeholder="'请选择接受交底人'"
              v-model="from.jsjdr"
              :prop="'jsjdr'"
          ></user-pick>
				</view>
				<view class="title">
					安全教育
				</view>
				<view class="box">
					<u-form-item label="计划性" prop="jhxs" borderBottom @click="show = true,showType = 10">
						<u--input v-model="from.jhxs" placeholder="选择计划性" border="none" disabled disabledColor="#ffffff"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
				</view>
				<view class="title">
					审核人/审核部门
				</view>
				<view class="box">
          <user-pick
              :label="'作业负责人'"
              :multiple="false"
              :title="'作业负责人'"
              :placeholder="'请选择接作业负责人'"
              v-model="from.zyfzr"
              :prop="'zyfzr'"
          ></user-pick>
          <user-pick
              :label="'所在单位意见'"
              :multiple="false"
              :title="'所在单位审批人'"
              :placeholder="'请选择所在单位审批人'"
              v-model="from.sprmc"
              :prop="'sprmc'"
          ></user-pick>
				</view>
				<view class="title">
					验收
				</view>
				<view class="box">
          <user-pick
              :label="'验收人'"
              :multiple="false"
              :title="'验收人'"
              :placeholder="'请选择验收人'"
              v-model="from.ysr"
              :prop="'ysr'"
          ></user-pick>
				</view>
			</u--form>
			<u-button type="primary" text="申请" @click="submit" class='but'></u-button>
		</view>
	</view>
</template>

<script>
import {
  getDepartmentAPI, restrictedWorklAPI,aboutWorkAPI
} from "../../../api/api";
import userPick from "@/pages/Components/userPick";
import UTextarea from "../../../uni_modules/uview-ui/components/u-textarea/u-textarea";
	export default {
    components: {
      UTextarea,
      userPick,
    },
		data() {
			return {
        dateTimeType:0,
        newData:new Date().getTime(),
        dateTimeShow:false,
				show: false,
				showType: 0,
				labelStyle: {
					color: '#666'
				},
				title: '',
				columns: [[]],
				from: {
          harm:[],
          safetyMeasures:[],
          personalProtection:[],
          zypmc:'',
					test: '',
					zysqdw: '',
          createTime:'',
          sqrq:'',//申请日期
          zysssj:'',
          sssj:'',
          zynnr:'',
          sxkjmc:'',
          zyr:'',
          qyfxsj:'',
          krqtfxsj2:'',
          zydw:'',
          zyfzr:'',
          sxkjnyyjzmc:'',
          gltszy:'',
          ydyhqyfxsj:'',
          yhyhydyhqyfxsj:'',
          harmfulGas:"",
          ydyhhgbz:'',
          ydyhqtyqhl:'',
          yhqtfxbw:'',
          ydyhfxjg:'',
          krqtfxsj:'',
          krqtmc:'',
          krqthgbz:'',
          krtqyqhl:'',
          krqtfxbw:'',
          krqtfxsj:'',
          fxr:'',
          whbs:'',
          aqcs:'',
          grypfh:'',
          aqjdr:'',
          jsjdr:'',
          jhxs:'',
          jhx:'',
          zyfzr:'',
          sprmc:'',
          ysr:'',
          sgfzr:''
				},
				actions: [{
						name: '男',
					},
					{
						name: '女',
					},
					{
						name: '保密',
					},
				],
				rules: {
					// 'userInfo.name': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写姓名',
					// 	trigger: ['blur']
					// },
				},
				radio: '',
				switchVal: false
			};
		},
		watch: {
			showType(val) {
				if (val === 1 || val === 4) {
					getDepartmentAPI({}).then((r) => {
						let msg = r.data.map((e) => {
							return e.deptName
						})
						this.columns = [msg]
					})
				}else if (val === 2 || val === 3 || val === 5 || val === 7 || val === 8 ||val ===9 || val ===11 || val===12 ||val === 13 ){
          getDepartmentAPI({}).then((r) => {
            let msg = r.data.map((e) => {
              return e.deptName
            })
            let leader = r.data.map((e) => {
              return [e.leader]
            })
            this.columns = [msg, [r.data[0].leader]]
            this.columnData = leader
          })
        }else if(val === 6){
          // this.columns = [["动火安全作业票", "受限空间安全作业票", "盲板抽赌安全作业票", "高处安全作业票",'吊装安全作业票','临时用电安全作业票','动土安全作业票','断路安全作业票','设备检修安全作业票']]
          aboutWorkAPI({
            pageSize: 10000,
            pageNum: 1
          }).then((r) => {
            let msg = r.data.list.map((e) => {
              return e.zypmc
            })
            this.columns = [msg]
          })
				}else if (val === 10){
				  this.columns = [['非计划性','计划性']]
        }
			}
		},
    onShow() {
      let pages = getCurrentPages();
      let currPage = pages[pages.length - 1];
      let brand = currPage.brand
      if (!!brand) {
        if (brand.option) {
          this.from.harm = brand.option
          this.from.whbs = brand.optionList.toString()
        } else if (brand.list) {
          this.from.safetyMeasures = brand.list
          this.from.aqcs = brand.idList.toString()
        } else if (brand.fh) {
          this.from.personalProtection = brand.fh
          this.from.grypfh = brand.fhlist.toString()
        }
      }
    },
		methods: {
      toProtection(){
        uni.navigateTo({
          url:'../HotWork/protection/protection'
        })
      },
      toHazardousFactors() {
        uni.navigateTo({
          url: '../HotWork/hazardousFactors/hazardousFactors'
        })
      },
      toSafetyMeasures() {
        uni.navigateTo({
          url: '../HotWork/safetyMeasures/safetyMeasures'
        })
      },
      checkDateTime(e){
        const timeFormat = uni.$u.timeFormat
        if (this.dateTimeType === 1){
          this.from.createTime = timeFormat(e.value, 'yyyy-mm-dd hh:MM')
          this.from.sqrq = timeFormat(e.value, 'yyyymmddhhMM')
        }else if (this.dateTimeType === 2){
          this.from.zysssj = timeFormat(e.value, 'yyyy-mm-dd hh:MM')
          this.from.sssj = timeFormat(e.value, 'yyyymmddhhMM')
        }else if (this.dateTimeType === 3){
          this.from.ydyhqyfxsj = timeFormat(e.value, 'yyyy-mm-dd hh:MM')
          this.from.yhyhydyhqyfxsj = timeFormat(e.value, 'yyyymmddhhMM')
        }else if (this.dateTimeType === 4){
          this.from.krqtfxsj = timeFormat(e.value, 'yyyy-mm-dd hh:MM')
          this.from.krqtfxsj = timeFormat(e.value, 'yyyymmddhhMM')
        }
        this.dateTimeShow = false
      },
			confirm(e) {
        switch (this.showType){
          case 1:
            this.from.zysqdw=e.value[0]
                break;
            case 4:
              this.from.zydw =e.value[0]
                break;
              case 10:
              this.from.jhxs =e.value[0]
              this.from.jhxs =e.index[0]
                break;
        }
        if(this.showType === 1){
          this.from.zysqdw=e.value[0]
        }
        this.show = false
			},
			submit() {
        restrictedWorklAPI({...this.from}).then((r)=>{
          if (r.code === 200){
            this.$refs.uToast.show({
              type: 'success',
                  title: '成功主题(带图标)',
                message: "新增成功",
                iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
            })
            uni.navigateBack({
                  delta:1
                }
            )
          }
        })
			}
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 0 24rpx;
		background-color: #f6f6f6;

		.title {
			font-size: 28rpx;
			font-weight: 500;
			color: #999999;
			line-height: 44rpx;
			padding: 20rpx 48rpx;
		}

		.box {
			padding: 0rpx 48rpx;
			background-color: #fff;
			border-radius: 20rpx;
		}
	}

	.but {
		margin: 30rpx 0;
	}
</style>
